<template>
	<view>
		<uni-section title="录音" type="line">
			<view class="mtp15 center">
				<all-speech @startRecord="start" @endRecord="end" @cancelRecord="cancel"></all-speech>
			</view>
			<uni-row>
				<uni-col class="mtp15">
					<button type="primary" @click="play">播放</button>
				</uni-col>
			</uni-row>
		</uni-section>

	</view>
</template>

<script>
	const innerAudioContext = uni.createInnerAudioContext();
	export default {
		data() {
			return {
				title: 'Hello Uni App'
			}
		},
		onLoad() {

		},
		methods: {
			start() {
				// 开始录音
				console.log('开始录音')
			},
			end(event) {
				// 结束录音并处理得到的录音文件
				// event中，app端仅有tempFilePath字段，微信小程序还有duration和fileSize两个字段
				console.log(event)
				innerAudioContext.src = event.tempFilePath;
			},
			cancel() {
				// 用户取消录音
				console.log('用户取消录音')
				innerAudioContext.src = ''
			},
			play() {
				innerAudioContext.play();
			},
		}
	}
</script>

<style scoped lang="scss">
	.mtp15 {
		margin-top: 15rpx;
	}

	.center {
		text-align: center;
		display: flex;
		justify-content: center;
	}
</style>